package com.socodethis.spaceex;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.socodethis.spaceex.math.cPoint;

public class ProgressBarClass {
	Sprite Bar;
	Sprite[] Character;
	int progress, frame, fracD, fracN;
	cPoint Dimensions;
	Sprite chars;
	public ProgressBarClass(ProgressBarClass progress){
		this(progress.Dimensions, progress.Bar, progress.Character);
	}
	public ProgressBarClass(cPoint Dimensions,Sprite Bar, Sprite[] Character){
		this.Character = new Sprite[Character.length];
		for(int i = 0; i < Character.length; i++){
			this.Character[i] = new Sprite(Character[i]);
			this.Character[i].setSize(Character[i].getWidth()*3, Character[i].getHeight()*3);
		}
		this.Bar = new Sprite(Bar);
		this.Bar.setSize(Dimensions.getX(), Bar.getHeight()*2);
		this.Bar.setPosition(0, Gdx.graphics.getHeight()/10);
		progress = 0;
		frame = 0;
		this.Dimensions = new cPoint(Dimensions);
	}
	
	public Sprite getBar(){
		return Bar;
	}
	
	public int getProgress(){
		return progress;
	}
	
	public Sprite getCharacter(){
		chars = new Sprite(Character[frame]);
		chars.setPosition((((Dimensions.getX()-Character[frame].getWidth())/100) * progress), 20);
		return chars;
	}
	
	public void setProgress(int progress){
		if (progress >= 0 && progress < 101){
			this.progress = progress;
			frame++;
			if(frame == Character.length){
				frame = 0;
			}
		}
	}
	
	public void addProgress(){
		if (progress+1 < 101){
			progress++;
			if(progress % 5 == 0){
				frame++;
				if(frame == Character.length){
					frame = 0;
				}
			}
		}
		//System.out.println("progress");
		//System.out.println((Dimensions.getX()/100)*progress);
	}
	
	public void setFraction(int fraction){
		this.fracD = fraction;
		this.fracN = 0;
	}
	
	public void addFraction(){
		this.fracN++;
		progress = fracN/fracD;
	}
}
